<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form :form="form" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-item label="创建人" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['createBy']" placeholder="请输入创建人"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="创建日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择创建日期" v-decorator="['createTime']" :trigger-change="true" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="更新人" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['updateBy']" placeholder="请输入更新人"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="更新日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择更新日期" v-decorator="['updateTime']" :trigger-change="true" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="项目编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['xmbh']" placeholder="请输入项目编号"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="项目协议编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['xmxybh']" placeholder="请输入项目协议编号"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="项目名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['xmmc']" placeholder="请输入项目名称"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="项目类型代码" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag type="list" v-decorator="['xmlxid']" :trigger-change="true" dictCode="hydm" placeholder="请选择项目类型代码"/>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="项目类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['xmlx']" placeholder="请输入项目类型"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="项目内容" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-textarea v-decorator="['xmnr']" rows="4" placeholder="请输入项目内容"/>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="验收标准" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-textarea v-decorator="['ysbz']" rows="4" placeholder="请输入验收标准"/>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="项目总预算" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['xmzys']" placeholder="请输入项目总预算" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="任务总金额" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['rwzje']" placeholder="请输入任务总金额" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="平台综合服务费" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['ptfwf']" placeholder="请输入平台综合服务费" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="需要人数" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['xyrs']" placeholder="请输入需要人数" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="性别要求" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['xbyq']" placeholder="请输入性别要求" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="年龄要求" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['nlyq']" placeholder="请输入年龄要求" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="学历要求" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['xlyq']" placeholder="请输入学历要求" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="经验要求" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['jyyq']" placeholder="请输入经验要求" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="项目起始日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择项目起始日期" v-decorator="['xmqrq']" :trigger-change="true" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="项目终止日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择项目终止日期" v-decorator="['xmzrq']" :trigger-change="true" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="工作开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['gzkssj']" placeholder="请输入工作开始时间"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="工作结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['gzjssj']" placeholder="请输入工作结束时间"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="工作城市" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['gzcs']" placeholder="请输入工作城市"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="工作城市名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['gzcsmc']" placeholder="请输入工作城市名称"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="项目状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag type="list" v-decorator="['status']" :trigger-change="true" dictCode="project_status" placeholder="请选择项目状态"/>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="提交审核时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择提交审核时间" v-decorator="['tjsj']" :trigger-change="true" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="项目发布时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择项目发布时间" v-decorator="['fbsj']" :trigger-change="true" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="企业名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['gsmc']" placeholder="请输入企业名称"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="服务费率" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['fwfl']" placeholder="请输入服务费率"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="公司联系人手机" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['lxrsj']" placeholder="请输入公司联系人手机"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="公司联系人姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['lxrxm']" placeholder="请输入公司联系人姓名"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="注册地址" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['zcdz']" placeholder="请输入注册地址"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="纳税人识别号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['sh']" placeholder="请输入纳税人识别号"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="卡号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['kh']" placeholder="请输入卡号"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="邮箱" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['email']" placeholder="请输入邮箱"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="开户行" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['khh']" placeholder="请输入开户行"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="办公地址" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['bgdz']" placeholder="请输入办公地址"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="合同用5" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['charterptid']" placeholder="请输入合同用5"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="协议路径" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['htpdf']" placeholder="请输入协议路径"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="合同用2" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['presonalid']" placeholder="请输入合同用2"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="合同用6" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['enterpriseid']" placeholder="请输入合同用6"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="合同用7" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['presonalptid']" placeholder="请输入合同用7"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="合同用1" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['enterpriseptid']" placeholder="请输入合同用1"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="合同用3" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['contractno']" placeholder="请输入合同用3"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="合同用8" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['charterid']" placeholder="请输入合同用8"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="合同用4" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['procedureno']" placeholder="请输入合同用4"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="合同编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['htbh']" placeholder="请输入合同编号"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="数据来源" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['sjly']" placeholder="请输入数据来源"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="驿站名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['yzmc']" placeholder="请输入驿站名称"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="招聘方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['zpfs']" placeholder="请输入招聘方式"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="急招:0否, 1是" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['isUrgent']" placeholder="请输入急招:0否, 1是"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="热招:0否, 1是" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['isHot']" placeholder="请输入热招:0否, 1是"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="距离" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['distance']" placeholder="请输入距离" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="地点经度" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['longitude']" placeholder="请输入地点经度" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="地点纬度" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['latitude']" placeholder="请输入地点纬度" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="筛选" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['workscreening']" placeholder="请输入筛选"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="企业类型(1驿站,2人力资源,3企业)" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['qylx']" placeholder="请输入企业类型(1驿站,2人力资源,3企业)"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="结算方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['jsfs']" placeholder="请输入结算方式"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="已报名人数" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['ybmrs']" placeholder="请输入已报名人数" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="已录用人数" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['ylyrs']" placeholder="请输入已录用人数" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="工作环境照片" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['workplaceImg']" placeholder="请输入工作环境照片"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="是否结算，0不通过平台，1外包, 2代发工资" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['isjs']" placeholder="请输入是否结算，0不通过平台，1外包, 2代发工资"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="驳回理由" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['reason']" placeholder="请输入驳回理由"></a-input>
            </a-form-item>
          </a-col>
          <a-col v-if="showFlowSubmitButton" :span="24" style="text-align: center">
            <a-button @click="submitForm">提 交</a-button>
          </a-col>
        </a-row>
      </a-form>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JFormContainer from '@/components/jeecg/JFormContainer'
  import JDate from '@/components/jeecg/JDate'  
  import JDictSelectTag from "@/components/dict/JDictSelectTag"

  export default {
    name: 'YzProjectForm',
    components: {
      JFormContainer,
      JDate,
      JDictSelectTag,
    },
    props: {
      //流程表单data
      formData: {
        type: Object,
        default: ()=>{},
        required: false
      },
      //表单模式：true流程表单 false普通表单
      formBpm: {
        type: Boolean,
        default: false,
        required: false
      },
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        form: this.$form.createForm(this),
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/yzproject/yzProject/add",
          edit: "/yzproject/yzProject/edit",
          queryById: "/yzproject/yzProject/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return false
          }
          return true
        }
        return this.disabled
      },
      showFlowSubmitButton(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return true
          }
        }
        return false
      }
    },
    created () {
      //如果是流程中表单，则需要加载流程表单data
      this.showFlowData();
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'createBy','createTime','updateBy','updateTime','xmbh','xmxybh','xmmc','xmlxid','xmlx','xmnr','ysbz','xmzys','rwzje','ptfwf','xyrs','xbyq','nlyq','xlyq','jyyq','xmqrq','xmzrq','gzkssj','gzjssj','gzcs','gzcsmc','status','tjsj','fbsj','gsmc','fwfl','lxrsj','lxrxm','zcdz','sh','kh','email','khh','bgdz','charterptid','htpdf','presonalid','enterpriseid','presonalptid','enterpriseptid','contractno','charterid','procedureno','htbh','sjly','yzmc','zpfs','isUrgent','isHot','distance','longitude','latitude','workscreening','qylx','jsfs','ybmrs','ylyrs','workplaceImg','isjs','reason'))
        })
      },
      //渲染流程表单数据
      showFlowData(){
        if(this.formBpm === true){
          let params = {id:this.formData.dataId};
          getAction(this.url.queryById,params).then((res)=>{
            if(res.success){
              this.edit (res.result);
            }
          });
        }
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'createBy','createTime','updateBy','updateTime','xmbh','xmxybh','xmmc','xmlxid','xmlx','xmnr','ysbz','xmzys','rwzje','ptfwf','xyrs','xbyq','nlyq','xlyq','jyyq','xmqrq','xmzrq','gzkssj','gzjssj','gzcs','gzcsmc','status','tjsj','fbsj','gsmc','fwfl','lxrsj','lxrxm','zcdz','sh','kh','email','khh','bgdz','charterptid','htpdf','presonalid','enterpriseid','presonalptid','enterpriseptid','contractno','charterid','procedureno','htbh','sjly','yzmc','zpfs','isUrgent','isHot','distance','longitude','latitude','workscreening','qylx','jsfs','ybmrs','ylyrs','workplaceImg','isjs','reason'))
      },
    }
  }
</script>